import { reactive } from "vue";
import type { FormRules } from "element-plus";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  title: [
    { required: true, message: "标题为必填项", trigger: "blur" },
    { max: 20, message: "标题不能超过20字", trigger: "blur" }
  ],
  receivers: [{ required: true, message: "收件人为必填项", trigger: "blur" }],
  content: [
    { required: true, message: "内容为必填项", trigger: "blur" },
    {
      validator: async (_, value, callback) => {
        if (value === "" || value === "<p><br></p>") {
          callback(new Error("内容为必填项"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ]
});
